package mt;

import java.util.Scanner;

/**
 * @author zhangmin
 * @create 2022-03-16 20:59
 */
public class meituan2021_1_3 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int value=0,cost=0;
        for (int i = 0; i < n; i++) {
            int x=cin.nextInt();
            int y=cin.nextInt();
            if(x<=y){
                value+=y;
            }else{
                value+=x;
                cost+=(x-y);
            }
        }
        System.out.println(value+" "+cost);
    }
}
